package cn.tworice.admin.web;

import cn.tworice.admin.service.LogService;
import cn.tworice.admin.service.LoginService;
import cn.tworice.admin.service.SystemService;
import cn.tworice.common.entity.Admin;
import cn.tworice.common.entity.Role;
import cn.tworice.common.entity.Resources;
import cn.tworice.common.entity.RoleResources;
import cn.tworice.common.entity.dto.ResourcesDto;
import cn.tworice.common.utils.CodeUtil;
import cn.tworice.common.utils.SystemInfoUtil;
import cn.tworice.common.vo.RequestResult;
import cn.tworice.common.vo.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * 系统管理模块 接口
 *
 * @author 二饭
 * @email 1786705138@qq.com
 */
@RestController
@RequestMapping("admin/system")
@Slf4j
@CrossOrigin
@Api("系统工具")
public class SystemController {

    @Autowired
    private SystemService systemService;

    @Autowired
    private LoginService loginService;

    @Autowired
    private LogService logService;


    @GetMapping("online")
    public RequestResult online(){
        RequestResult result = new RequestResult();
        result.appendData("list", systemService.getAdminMap());
        return result;
    }

    /**
     * 使该Key失效
     * @param key
     * @return
     */
    @DeleteMapping("offline")
    public RequestResult offline(String key){
        RequestResult result = new RequestResult();
        systemService.delAdminMap(key);
        return result;
    }

    /**
     * 获取系统信息
     * @author 二饭[tworice@sina.cn][2022/1/7 21:20]
     */
    @GetMapping("systemInfo")
    public RequestResult systemInfo(){
        RequestResult result = new RequestResult();
        SystemInfoUtil systemInfoUtil = new SystemInfoUtil();
        List systemInfo = systemInfoUtil.getSystemInfo();
        result.appendData("systemInfo",systemInfo);
        result.appendData("memoryInfo",systemInfoUtil.getMemoryInfo());
        result.appendData("processInfo",systemInfoUtil.getProcessInfo());
        result.appendData("cpuInfo",systemInfoUtil.getCpuInfo());
        return result;
    }
}
